(function (window) {
	//定义请求的函数
	const request = async function (url,method = "get",data = {}) {
		//get请求的处理
		if (method == "get") {
			//判断是否有参数
			if (JSON.stringify(data) == "{}") {
				//没有参数直接发送请求
				let res = await fetch(url).then(req => req.json());
				return res;
			} else{
				//有参数将参数处理成 get拼接的参数
				let arr = [];
				Object.keys(data).forEach(key=>arr.push(key+"="+data[key]));
				url += "?" + arr.join("&");
				let res = await fetch(url).then(req => req.json());
				return res;
			}
		}
		//post请求的处理
		if (method == "post") {
			//判断是否有参数
			if (JSON.stringify(data) == "{}") {
				//没有参数直接发送请求
				let res = await fetch(url).then(req => req.json());
				return res;
			} else{
				//有参数将参数处理成 get拼接的参数
				let body = new FormData();
				Object.keys(data).forEach(key=>body.append(key,data[key]));
				let res = await fetch(url,{
					method,
					body
				}).then(req => req.json());
				return res;
			}
		}
		//delete请求的处理
		
		//put请求的处理
	}
	//基础请求地址
	const baseUrl = "./api/Account.php";
	//GetAll （get）获取所有文章
	const getAll = function () {
		return request(`${baseUrl}/GetAll`,"get")
	};
	//GetAllTittle （get）获取所有文章标题
	const getAllTittle = function () {
		return request(`${baseUrl}/GetAllTittle`,"get")
	};
	//GetOneArticle （get）根据show_id 获取对应的文章信息
	const getOneArticle = function (data) {
		return request(`${baseUrl}/GetOneArticle`,"get",data)
	};
	const getOneArticle2 = function (data) {
		return request(`../.${baseUrl}/GetOneArticle`,"get",data)
	};
	//Login （post）登陆功能
	const login = function (data) {
		return request(`${baseUrl}/Login`,"post",data)
	};
	//Register （post）注册功能
	const register = function (data) {
		return request(`${baseUrl}/Register`,"post",data)
	}
	//校验用户身份
	const checkUser = function (data) {
		return request(`${baseUrl}/CheckUser`,"post",data)
	}
	
	//获取统计数据
	const articleCount = function () {
		return request(`${baseUrl}/ArticleCount`,"get")
	}
	
	//删除的功能
	const articleDelete = function (data) {
		return request(`../.${baseUrl}/Delete `,"post",data)
	}
	
	//添加的功能
	const articleInsert = function (data) {
		return request(`../.${baseUrl}/Insert  `,"post",data)
	}
	
	//更新文章的功能
	const articleUpdate = function (data) {
		return request(`../.${baseUrl}/Update  `,"post",data)
	}
	window.$$ = {
		getAll,
		getAllTittle,
		getOneArticle,
		getOneArticle2,
		login,
		register,
		checkUser,
		articleCount,
		articleDelete,
		articleInsert,
		articleUpdate
	}
})(window)